package sjtu.ist.warehouse4ws.action;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;



import sjtu.ist.warehouse4ws.model.Domainmodel;
import sjtu.ist.warehouse4ws.model.Epcunits;
import sjtu.ist.warehouse4ws.service.EpcunitsService;
import sjtu.ist.warehouse4ws.service.PrivilegeService;





import com.googlecode.jsonplugin.annotations.JSON;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class ShowEpcListAction extends ActionSupport {
	private EpcunitsService epcUnitsService;
	private PrivilegeService privilegeService;
	private List<Epcunits> epcUnitsList = new ArrayList<Epcunits>();
	
	
	//获得EpcUnits列表
	public String showEpcList(){
		List<Epcunits> templist=epcUnitsService.getEpcunitsList();
		this.epcUnitsList = new ArrayList<Epcunits>();
		
		ActionContext actionContext=ActionContext.getContext();
		Map session=actionContext.getSession();		
		int userType=(Integer)(session.get("user_type"));
		String userCompany=session.get("user_company").toString();		
		
		for(Epcunits e : templist){
			if(privilegeService.checkPrivilege(e.getFileId(),userCompany,userType, "read")){
				epcUnitsList.add(e);
			}
		}
		return SUCCESS;
	}
	
	@JSON(name = "totalEpcUnits")
	public int getTotalDomainModel() {
		return this.epcUnitsList.size();
	}

	@JSON(name = "EpcUnits")
	public List<Epcunits> getEpcUnitsList() {
		return this.epcUnitsList;
	}
	
	// 注入EpcUnitsService
	public void setEpcunitsService(EpcunitsService epcUnitsService) {
		this.epcUnitsService = epcUnitsService;
	}

	public void setPrivilegeService(PrivilegeService privilegeService) {
		this.privilegeService = privilegeService;
	}
}
